using System;
using System.Linq;
using NUnit.Framework;
using SharpTestsEx;

namespace AltNetHispano.Vale.Tests
{
	public class PolimorphismTests
	{
		public class Contact
		{
			public string Name { get; set; }
		}

		public class Person: Contact
		{
			public string Surname { get; set; }
		}

		public interface IDomesticAnimal
		{
			string Name { get; set; }
		}

		public class DomesticAnimal: IDomesticAnimal
		{
			public string Name
			{
				get; set;
			}
		}

		[Test]
		public void WhenValidatePersonThenShouldApplyRulesOfContact()
		{
			var validator = new Validator();
			validator.Register<Contact>(c=> validator.StringIsRequired("Name", c.Name));
			validator.Register<Person>(p => validator.StringIsRequired("Surname", p.Surname));

			var person = new Person();
			var invalidMessages = validator.GetInvalidMessages(person).ToArray();
			invalidMessages.Should().Have.Count.EqualTo(2);
		}

		[Test]
		public void WhenRegisterValidationForInterfaceThenShouldApplyRulesToItsInstances()
		{
			var validator = new Validator();
			validator.Register<IDomesticAnimal>(da => validator.StringIsRequired("Name", da.Name));

			var person = new DomesticAnimal();
			var invalidMessages = validator.GetInvalidMessages(person).ToArray();
			invalidMessages.Should().Have.Count.EqualTo(1);
		}
	}
}